package view.ui 
{
	import comp.display.Window;
	import event.ShowPanelEvent;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import model.data.NiaoyuEntry;
	import model.data.NiaoyuIdea;
	
	/**
	 * ...
	 * @author Qi Donghui
	 */
	public class ListView extends Sprite 
	{
		/**
		 * 白色带投影的底
		 */
		private var _bg:MovieClip;
		
		/**
		 * 列表的容器
		 */
		private var _cont:Sprite;
		
		/**
		 * 列表容器的遮罩
		 */
		private var _msk:Sprite;
		
		private var _arrEntryItem:Array;
		
		public function ListView() 
		{
			addEventListener(Event.ADDED_TO_STAGE, onAddToStage);
		}
		
		private function onAddToStage(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, onAddToStage);
			_bg = new SKcontentLBg();
			_bg.x = -8;
			addChild(_bg);
			
			this.y = 47;
			onStageResize();
			stage.addEventListener(Event.RESIZE, onStageResize);
			
			//this.graphics.beginFill(0x00ff00, 0.5)
			//this.graphics.drawRect(0, 47, 608, stage.stageHeight - 47);
			//this.graphics.endFill();
			
			_cont = new Sprite();
			_cont.y = 120;
			addChild(_cont);
			
			_arrEntryItem = [];
			var theight:Number = 0;
			for (var i:int = 0; i < 20; i ++)
			{
				var ne:NiaoyuEntry = new NiaoyuEntry();
				ne.word = "astonish";
				ne.explain = "vt.使惊讶，使吃惊	adj.特惊讶，倍儿吃惊	adv.惊讶的，吃惊的";
				if (i == 1)
				{
					var idea:NiaoyuIdea = new NiaoyuIdea();
					idea.content = '“尔康”发现自己在网络再度火爆非常吃惊。\n"Erkang" ws astonished when he found himself to be popular agian sss...';
					idea.picture = "test/ideaPic.jpg";
					idea.name = "啧啧V";
					ne.arrIdeas = [];
					ne.arrIdeas.push(idea);
				}
				var ei:EntryItem = new EntryItem(ne);
				ei.addEventListener(Event.CHANGE, onEntryItemChange);
				ei.addEventListener(ShowPanelEvent.SHOW_ADD_IDEA_PANEL, onShowPanel);
				ei.render();
				_arrEntryItem.push(ei);
				ei.y = theight;
				_cont.addChild(ei);
				theight += ei.height - 1;
			}
		}
		
		////////////////////////////////////////////////////////////
		//// 共有函数
		////////////////////////////////////////////////////////////		
		
		////////////////////////////////////////////////////////////
		//// 事件处理
		////////////////////////////////////////////////////////////
		private function onStageResize(evt:Event = null):void
		{
			_bg.height = stage.stageHeight - 47;
			if (stage.stageWidth < 960) this.x = 0;
			else {
				this.x = stage.stageWidth - 0.5 * (stage.stageWidth  - 960) - 960;
			}				
		}		
		
		private function onEntryItemChange(e:Event):void 
		{
			var ei:EntryItem = e.currentTarget as EntryItem;
			var id:int = _arrEntryItem.indexOf(ei);
			var theight:Number = ei.y + ei.height - 1;
			for (var i:int = id + 1, len:int = _arrEntryItem.length; i < len; i ++)
			{
				ei = _arrEntryItem[i];
				ei.y = theight;
				theight += ei.height - 1;
			}
		}		
		
		private function onShowPanel(e:ShowPanelEvent):void 
		{
			dispatchEvent(e.clone());
		}		
		
		////////////////////////////////////////////////////////////
		//// Set和Get函数
		////////////////////////////////////////////////////////////		
		
	}

}